package jp.sinya.temicontact.utils;

import com.pubnub.api.PNConfiguration;
import com.pubnub.api.PubNub;

import static jp.sinya.temicontact.constants.Constants.PUBLISH_KEY;
import static jp.sinya.temicontact.constants.Constants.SUBSCRIBE_KEY;

/**
 * @author Koizumi Sinya
 * @date 2018/01/12. 22:36
 * @edithor
 * @date
 */
public class PubnubUtils {
    private static PubnubUtils instance;
    private PubNub pubnub;

    private PubnubUtils() {
    }

    public static PubnubUtils getInstance() {
        if (instance == null) {
            synchronized (PubnubUtils.class) {
                instance = new PubnubUtils();
            }
        }
        return instance;
    }

    public void init() {
        PNConfiguration pnConfiguration = new PNConfiguration();
        pnConfiguration.setSubscribeKey(SUBSCRIBE_KEY);
        pnConfiguration.setPublishKey(PUBLISH_KEY);
        pubnub = new PubNub(pnConfiguration);
    }

    public PubNub getPubNub() {
        if (pubnub == null) {
            init();
        }
        return pubnub;
    }
}
